﻿<%@ include file="../include/top.jsp" %>
<%@ include file="../include/errorArea.jsp" %>

<link rel="stylesheet" href="${baseURL}/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script language="javascript" type="text/javascript" src="${baseURL}/js/jquery.ztree.all-3.5.min.js">
</script>
<SCRIPT type="text/javascript">
	var setting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClick
		}
	};

	var zNodes = ${treedata}; //后台返回的数据

	function onClick(e,treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(treeNode);

		//叶节点，并且不是第一层节点(第一层节点的pId是null)
		if(!treeNode.isParent && treeNode.pId!=null){
			nodes = zTree.getSelectedNodes();
			$("#selectedNodeName").attr("value", treeNode.name);
			$("#nodeId").attr("value", treeNode.id);
		}
	}

	function showMenu() {
		var cityObj = $("#selectedNodeName");
		var cityOffset = $("#selectedNodeName").offset();
		$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "selectedNodeName" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}

	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getNodesByParam("id", "${formdata.nodeId}", null);
		if (nodes.length>0) {
			treeObj.selectNode(nodes[0]);
		}

	});
</SCRIPT>

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" style="margin-top:10px;">
            <tr>
              <td colspan="2" align="left" valign="middle" class="text_gray2">
              
              <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#96bee2">
                  <tr>
                    <td height="21" background="${baseURL}/images/table_bg.jpg">&nbsp;&nbsp;<span class="text_blue_b"><c:if test="${empty formdata.id || formdata.id==0}"><img src="${baseURL}/images/bit_add.png" width="16" height="14" border="0" align="absmiddle" />
添加商品</c:if> 
	  <c:if test="${not empty formdata.id && formdata.id>0}">
<img src="${baseURL}/images/bit_edit.png" width="16" height="14" border="0" align="absmiddle" /> 编辑商品</c:if></span></td>
                  </tr>
                  <tr>
                    <td height="13" align="center" valign="top" bgcolor="#FFFFFF">
					<form name="myForm" method="POST" action="${baseURL}/product/saveProduct">
					<input type="hidden" name="id" value="${formdata.id}" />
<table width="100%" border="0" align="center" id="listTable" bgcolor="#FFFFFF" cellpadding="1" cellspacing="0">
	<tr style="display:none">
	  <td colspan="2" height="0" >
	  </td>
    </tr>
    <tr>
		<td align="right">商品ID：</td>
		<td align="left">${formdata.id}</td>
	</tr>
    <tr>
		<td align="right">商品编码：</td>
		<td align="left"><input name="productCode" type="text" id="productCode"
			value="${formdata.productCode}" size="25" maxlength="50" /></td>
	</tr>
	<tr>
		<td align="right"><span class="mustInput">*</span>商品名称 ：</td>
		<td align="left"><input name="productName" type="text" id="productName"
			value="${formdata.productName}" size="70" maxlength="50" /></td>
    </tr>
	<tr>
	  <td align="right" width="120"><span class="mustInput">*</span>商品所属分类：</td>
      <td align="left" colspan="3"><input type="hidden" name="nodeId" id="nodeId" value="${formdata.nodeId}"/>
			<input name="selectedNodeName" id="selectedNodeName" type="text" readonly value="${formdata.selectedNodeName}" size="40" onclick="showMenu()"/>
		<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
			<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px;"></ul>
		</div>	</td>
    </tr>
    <tr>
		<td align="right">供货商：</td>
		<td align="left">${formdata.supplierId}</td>
	</tr>
	<tr>
		<td align="right">库存数量：</td>
		<td align="left">${formdata.stockNumber}</td>
	</tr>
	<tr>
		<td align="right">销售数量：</td>
		<td align="left">${formdata.sellNumber}</td>
	</tr>
    <tr> 
      <td align="right">商品介绍： </td>
	  <td>
			 <link rel="stylesheet" href="${baseURL}/kindeditor417/themes/default/default.css" />
			<link rel="stylesheet" href="${baseURL}/kindeditor417/plugins/code/prettify.css" />
			<script charset="utf-8" src="${baseURL}/kindeditor417/kindeditor-all-min.js"></script>
			<script charset="utf-8" src="${baseURL}/kindeditor417/lang/zh_CN.js"></script>
			<script charset="utf-8" src="${baseURL}/kindeditor417/plugins/code/prettify.js"></script>
			<script>
			KindEditor.ready(function(K) {
				editor1 = K.create('textarea[name="productContent"]', {
				cssPath : '${baseURL}/kindeditor417/plugins/code/prettify.css',
				uploadJson : '${baseURL}/kindeditor417/jsp/upload_json.jsp',
				fileManagerJson : '${baseURL}/kindeditor417/jsp/file_manager_json.jsp',
				allowFileManager : true,
						afterCreate : function() {
							var self = this;
							K.ctrl(document, 13, function() {
								self.sync();
								K('form[name=myForm]')[0].submit();
							});
							K.ctrl(self.edit.doc, 13, function() {
								self.sync();
								K('form[name=myForm]')[0].submit();
							});
						}
					});
					prettyPrint();
				});
			</script>
	  <textarea name="productContent" cols="60" rows="5" class="myInput" id="productContent">${formdata.productContent}</textarea></td>
    </tr>
    <!-- 
	<tr>
		<td align="right">商品图片1</td>
		<td align="left"><input name="productPic1" type="file" class="myInput" id="productPic1"></td>
	</tr>
	<tr>
		<td align="right">商品图2</td>
		<td align="left"><input name="productPic2" type="file" class="myInput" id="productPic2"></td>
	</tr>
	<tr>
		<td align="right">商品图片3</td>
		<td align="left"><input name="productPic3" type="file" class="myInput" id="productPic3"></td>
	</tr>
	<tr>
		<td align="right">商品图片4</td>
		<td align="left"><input name="productPic4" type="file" class="myInput" id="productPic4"></td>
	</tr>
	<tr>
		<td align="right">商品图片5</td>
		<td align="left"><input name="productPic5" type="file" class="myInput" id="productPic5"></td>
	</tr> -->
	<tr>
	  <td align="right">供货商的价格：</td>
      <td align="left"><span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td>
	</tr>
	<tr>
	  <td align="right">加价比例：</td>
      <td align="left">
      	<select name="addPercent" id="addPercent" onChange="countPrice()">
		      <c:forEach var="i" begin="1" end="100">
		      	<option value="${i}">${i}</option>
		      </c:forEach>
	       </select>% 仅用作计算，最终价格以下面的零售价格为准。</td>
	</tr>
	<tr>
	  <td align="right">零售价格：</td>
      <td align="left"><input name="sellPrice" id="sellPrice" type="text" id="sellPrice"
			value="${formdata.sellPrice}" size="25" maxlength="50" onblur="countPrice2()"/>元（人民币）
			实际加价比例：<span id="trueAddPercent"></span>%
		</td>
	</tr>
	<tr>
	  <td align="right">分成百分比：</td>
      <td align="left">
	      <select name="sharePercent">
		      <c:forEach var="i" begin="1" end="100">
		      	<option value="${i}">${i}</option>
		      </c:forEach>
	      </select>% 利润部分，给物业的分成百分比
      </td>
	</tr>
	<tr> 
      <td align="right">备注： </td>
      <td><textarea name="remark" cols="50" rows="5" class="myInput" id="remark">${formdata.remark}</textarea></td>
    </tr>
	<tr>
	  <td align="right">其它：</td>
      <td align="left">
      	<label><input name="recommendFlag" id="recommendFlag" type="checkbox" class="myInput" value="1"/>推荐商品</label>
      	<label><input name="specialPriceFlag" id="specialPriceFlag" type="checkbox" class="myInput" value="1"/>特价商品</label>
      </td>
	</tr>

	<tr>
	  <td colspan="2" align="center">
	  	<input name="submit" type="submit" value="提交" class="myButton" onclick="editor1.sync()"/>
	    &nbsp;&nbsp;
        <input name="button" type="button"
			onclick="history.go(-1)" value="返回" class="myButton"/></td>
    </tr>
	<tr>
	  <td colspan="4" align="center">&nbsp;</td>
    </tr>
</table>
</form></td>
                  </tr>
              </table></td>
            </tr>
</table>
<script>
doSelect(myForm.addPercent,"${formdata.addPercent}");
doSelect(myForm.sharePercent,"${formdata.sharePercent}");
$("#recommendFlag").attr("checked", "${formdata.recommendFlag}"=="1");
$("#specialPriceFlag").attr("checked", "${formdata.specialPriceFlag}"=="1");

//计算价格，总是向上取整
function countPrice(){
	var oldPrice = parseFloat($('#supplierPrice').html());
	var finalPercent = 1 + 0.01 * parseInt($('#addPercent').val());
	$('#sellPrice').val(Math.ceil(oldPrice * finalPercent));
	
	countPrice2();
}
//计算实际的加价比例
function countPrice2(){
	var oldPrice = parseFloat($('#supplierPrice').html());
	var finalPrice = parseFloat($('#sellPrice').val());
	var finalPercent = (finalPrice - oldPrice)/oldPrice * 100;
	$('#trueAddPercent').html(finalPercent);
}
</script>
<%@ include file="../include/bottom.jsp" %>